package com.zuihai.app.mvp.model.entity;

import android.os.Parcel;
import android.os.Parcelable;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.zuihai.app.mvp.constant.HomeConstant;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/5/4 0004.
 */

public class HomeItem implements MultiItemEntity, Parcelable {
    @SerializedName(value = "tiaomu_id", alternate = "uid")
    @Expose
    public String id;
    @SerializedName("picture")
    @Expose
    public List<Picture> picture;//图片集
    @SerializedName("title")
    @Expose
    public String title;//标题
    @SerializedName(value = "name")
    @Expose
    public String name;//作者名称
    @SerializedName("content")
    @Expose
    public String content;//内容
    @SerializedName(value = "muban_Tag")
    @Expose
    public Integer itemType;//列表类型
    @SerializedName("laiyuan")
    @Expose
    public String source;//来源
    @SerializedName("dianzan_count")
    @Expose
    public int favour;//点赞
    @SerializedName("pinglun_count")
    @Expose
    public int commentCount;//评论量
    @SerializedName("time")
    @Expose
    public String time;//发表时间
    @SerializedName("url")
    @Expose
    public String url;//广告链接
    @SerializedName("url_Tag")
    @Expose
    public int urlTag;//内链还是外联（内链1外联2）
    @SerializedName("guangjie_fenlei_Tag")
    @Expose
    public int commodityType;
    @SerializedName("fenlei_Tag")
    @Expose
    public int adType;


    @Override
    public String toString() {
        return "HomeItem{" +
                "id='" + id + '\'' +
                ", picture=" + picture +
                ", title='" + title + '\'' +
                ", urlTag='" + urlTag + '\'' +
                ", url='" + url + '\'' +
                ", name='" + name + '\'' +
                ", content='" + content + '\'' +
                ", itemType=" + itemType +
                ", source=" + source +
                ", favour=" + favour +
                ", commentCount=" + commentCount +
                ", time=" + time +
                '}';
    }

    @Override
    public int getItemType() {
        if (itemType == HomeConstant.TWO_TYPE || itemType == HomeConstant.ONE_TYPE) {
            if (picture.size() == 3) {
                return HomeConstant.ONE_TYPE;
            } else {
                return HomeConstant.TWO_TYPE;
            }
        }
        return itemType;
    }

    public static class Picture {
        @SerializedName("picture_url")
        @Expose
        public String url;
    }

    public static class Favour implements Parcelable {
        @SerializedName("dianzan_count")
        @Expose
        public String count;

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(this.count);
        }

        public Favour() {
        }

        protected Favour(Parcel in) {
            this.count = in.readString();
        }

        public static final Creator<Favour> CREATOR = new Creator<Favour>() {
            @Override
            public Favour createFromParcel(Parcel source) {
                return new Favour(source);
            }

            @Override
            public Favour[] newArray(int size) {
                return new Favour[size];
            }
        };
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeList(this.picture);
        dest.writeString(this.title);
        dest.writeString(this.name);
        dest.writeString(this.content);
        dest.writeValue(this.itemType);
        dest.writeString(this.source);
        dest.writeInt(this.favour);
        dest.writeValue(this.commentCount);
        dest.writeString(this.time);
    }

    public HomeItem() {
    }

    protected HomeItem(Parcel in) {
        this.id = in.readString();
        this.picture = new ArrayList<Picture>();
        in.readList(this.picture, Picture.class.getClassLoader());
        this.title = in.readString();
        this.name = in.readString();
        this.content = in.readString();
        this.itemType = (Integer) in.readValue(Integer.class.getClassLoader());
        this.source = in.readString();
        this.favour = in.readInt();
        this.commentCount = (Integer) in.readValue(Integer.class.getClassLoader());
        this.time = in.readString();
    }

    public static final Parcelable.Creator<HomeItem> CREATOR = new Parcelable.Creator<HomeItem>() {
        @Override
        public HomeItem createFromParcel(Parcel source) {
            return new HomeItem(source);
        }

        @Override
        public HomeItem[] newArray(int size) {
            return new HomeItem[size];
        }
    };
}
